package cn.neusoft.luofa603.yuejian_29.fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import java.util.List;
import cn.neusoft.luofa603.yuejian_29.R;
import cn.neusoft.luofa603.yuejian_29.activity.ClubInfoActivity;
import cn.neusoft.luofa603.yuejian_29.adapter.ClubAdapter;
import cn.neusoft.luofa603.yuejian_29.bean.Club;
import cn.neusoft.luofa603.yuejian_29.model.ClubModel;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class RenQiFragment extends Fragment {

    private View view;
    private String hits;
    private RecyclerView recyclerView;
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_renqi, container, false);
        initviews();
        initEvents();
        initData();
        return view;
    }

    public void initviews(){
        recyclerView = (RecyclerView) view.findViewById(R.id.rv_club);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        recyclerView.setItemAnimator(new DefaultItemAnimator());

    }
    public void initEvents(){
        ClubModel clubModel = new ClubModel();
        Call<List<Club>> call= clubModel.getClub();
        call.enqueue(new Callback<List<Club>>() {
            @Override
            public void onResponse(Call<List<Club>> call, Response<List<Club>> response) {
                final List<Club> mDataList = response.body();
                ClubAdapter clubAdapter  = new ClubAdapter(getActivity(),mDataList);
                recyclerView.setAdapter(clubAdapter);
                clubAdapter.setItemClickListener(new ClubAdapter.MyItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        Intent intent = new Intent();
                        intent.setClass(getActivity(), ClubInfoActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("club",mDataList.get(position));
                        intent.putExtras(bundle);
                        startActivity(intent);
                    }
                });
            }

            @Override
            public void onFailure(Call<List<Club>> call, Throwable t) {
                Toast.makeText(getActivity(),"网络连接失败。。。。。。",Toast.LENGTH_SHORT).show();

            }
        });

    }
    public void initData(){

    }
}
